module Maze
  module TextFormatter
    class Orthogonal
      include DrawingHelpers

      attr_reader :maze, :canvas

      def initialize(maze)
        @maze   = maze
        @canvas = Array.new(maze.height + 1) do
          Array.new(maze.width * 2, ' ')
        end

        canvas_draw
      end

      private

      def calculate_origin(for_point)
        for_point.update do |other|
          other.x *= 2
          other.y += 1
        end
      end

      def calculate_offset(*args)
        direction = args.first

        case direction
        when maze.class::N then Point.new(1, -1)
        when maze.class::W then Point.new(0, 0)
        when maze.class::S then Point.new(1, 0)
        when maze.class::E then Point.new(2, 0)
        end
      end

      def select_character(for_direction)
        case for_direction
        when maze.class::N, maze.class::S then "_"
        when maze.class::W, maze.class::E then "|"
        end
      end
    end
  end
end
